﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>项目信息</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css" />
    <script type="text/javascript"
            src="http://webapi.amap.com/maps?v=1.4.3&key=29dca330739166f3fa36b94ed48168ad&plugin=AMap.Autocomplete"></script>
    <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
    <link href="~/Scripts/jquery-easyui-1.4.4/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui-1.4.4/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "Pro", "KeyName": "ProInfo" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {
                        var toolbar = getToolBar(data);      //common.js
                        if (data.search) {     //判断是否有浏览权限
                            var oldSelectRoleId;   //上次点选的RoleId
                            $("#ui_Pro_dg").datagrid({
                                url: "/ProInfo/GetAllProInfo",
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                                idField: 'ProjectGuid',
                                fit: true,
                                pageList: [20, 40, 60, 80, 100],
                                frozenColumns: [[
                                                 { width: 100, title: '项目ID', field: 'ProjectGuid', hidden: true },
                                                 { width: 100, title: '项目编号', field: 'ProjectId' },
                                                 { width: 100, title: '项目名称', field: 'ProjectName' },
                                                 { width: 100, title: '项目负责人', field: 'ProjectManager' },
                                                 { width: 100, title: '联系电话', field: 'ProjectTel' },
                                                 {
                                                     width: 100, title: '签订日期', field: 'SignTime', formatter: function (date) {
                                                         var pa = /.*\((.*)\)/;
                                                         var unixtime = date.match(pa)[1].substring(0, 10);
                                                         return getTime(unixtime);
                                                     }
                                                 },
                                                 {
                                                     width: 100, title: '完工日期', field: 'CompletionTime', formatter: function (date) {
                                                         var pa = /.*\((.*)\)/;
                                                         var unixtime = date.match(pa)[1].substring(0, 10);
                                                         return getTime(unixtime);
                                                     }
                                                 },
                                                 {
                                                     width: 100, title: '验收日期', field: 'AcceptanceTime', formatter: function (date) {
                                                         var pa = /.*\((.*)\)/;
                                                         var unixtime = date.match(pa)[1].substring(0, 10);
                                                         return getTime(unixtime);
                                                     }
                                                 },
                                                 {
                                                     width: 100, title: '质保期', field: 'WarrantyTime', formatter: function (date) {
                                                         var pa = /.*\((.*)\)/;
                                                         var unixtime = date.match(pa)[1].substring(0, 10);
                                                         return getTime(unixtime);
                                                     }
                                                 },
                                                 { width: 100, title: '用户联系人', field: 'UserManager' },
                                                 { width: 100, title: '用户联系人电话', field: 'UserTel' },
                                                 { width: 100, title: '用户联系人地址', field: 'Address' },
                                                 { width: 100, title: '经度', field: 'Longitude' },
                                                 { width: 100, title: '纬度', field: 'Latitude' },

                                ]],
                                toolbar: toolbar.length == 0 ? null : toolbar,
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })
        });

        //添加项目信息
        function AddProInfo() {
            $("<div/>").dialog({
                id: "ui_Pro_add_dialog",
                href: "/ProInfo/ProAdd",
                title: "添加项目信息",
                height: 570,
                width: 910,
                modal: true,
                buttons: [{
                    id: "ui_Pro_add_btn",
                    text: '添 加',
                    handler: function () {
                        //alert('111');
                        $("#ProAddForm").form("submit", {
                            url: "/ProInfo/ProInfoAdd",
                            onSubmit: function (param) {
                                param.ProjectId = $("#txtProjectId").val();
                                param.ProjectName = $("#txtProjectName").val();
                                param.ProjectManager = $("#txtProjectManager").val();
                                param.ProjectTel = $("#txtProjectTel").val();
                                param.SignTime = $("#txtSignTime").datetimebox("getValue");
                                param.CompletionTime = $("#txtCompletionTime").datetimebox("getValue");
                                param.AcceptanceTime = $("#txtAcceptanceTime").datetimebox("getValue");
                                param.WarrantyTime = $("#txtWarrantyTime").datetimebox("getValue");
                                param.UserManager = $("#txtUserManager").val();
                                param.UserTel = $("#txtUserTel").val();
                                param.Describe = $("#txtDescribe").val();
                                param.Address = $("#txtAddress").val();
                                param.Longitude = $("#txtLongitude").val();
                                param.Latitude = $("#txtLatitude").val();
                                if ($(this).form('validate')) {
                                    $('#ui_Pro_add_btn').linkbutton('disable');
                                    return true;
                                }
                                else {
                                    $('#ui_Pro_add_btn').linkbutton('enable');   //恢复按钮
                                    return false;
                                }
                            },
                            success: function (data) {
                                var dataJson = eval('(' + data + ')');
                                if (dataJson.success) {
                                    $("#ui_Pro_add_dialog").dialog('destroy');
                                    $.show_alert("提示", dataJson.msg);
                                    $("#ui_Pro_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $('#ui_Pro_add_btn').linkbutton('enable');
                                    $.show_alert("提示", dataJson.msg);
                                }
                            }
                        });
                    }
                }, {
                    text: '取 消',
                    handler: function () {
                        $("#ui_Pro_add_dialog").dialog('destroy');
                    }
                }],
                onLoad: function () {
                    $("#txtUserIDAdd").focus();
                },
                onClose: function () {
                    $("#ui_Pro_add_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }

        //修改项目信息
        function EditProInfo() {
            var rows = $("#ui_Pro_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先选择要修改的项目");
                return;
            }
            if (rows.length > 1) {
                $.show_alert("提示", "不支持批量修改项目");
                $("#ui_Pro_dg").datagrid('clearSelections').datagrid('clearChecked');
                return;
            }
            var id = "";
            $.each(rows, function (i, row) {
                id += row.ProjectGuid + ",";
            });

            id = id.substring(0, id.length - 1);
            //alert(id);
            $("<div/>").dialog({
                id: "ui_pro_edit_dialog",
                href: "/ProInfo/ProEdit?ProjectGuid=" + id,
                title: "修改项目信息",
                height: 570,
                width: 910,
                modal: true,
                buttons: [{
                    id: "ui_pro_edit_btn",
                    text: '修 改',
                    handler: function () {
                        $("#ProEditForm").form("submit", {
                            url: "/ProInfo/ProInfoEdit",
                            onSubmit: function (param) {
                                param.ProjectGuid = $("#txtProjectGuid").val();
                                param.ProjectId = $("#txtProjectId").val();
                                param.ProjectName = $("#txtProjectName").val();
                                param.ProjectManager = $("#txtProjectManager").val();
                                param.ProjectTel = $("#txtProjectTel").val();
                                param.SignTime = $("#txtSignTime").datetimebox("getValue");
                                param.CompletionTime = $("#txtCompletionTime").datetimebox("getValue");
                                param.AcceptanceTime = $("#txtAcceptanceTime").datetimebox("getValue");
                                param.WarrantyTime = $("#txtWarrantyTime").datetimebox("getValue");
                                param.UserManager = $("#txtUserManager").val();
                                param.UserTel = $("#txtUserTel").val();
                                param.Describe = $("#txtDescribe").val();
                                param.Address = $("#txtAddress").val();
                                param.Longitude = $("#txtLongitude").val();
                                param.Latitude = $("#txtLatitude").val();
                                if ($(this).form('validate')) {
                                    $('#ui_pro_edit_btn').linkbutton('disable');
                                    return true;
                                }
                                else {
                                    $('#ui_pro_edit_btn').linkbutton('enable');   //恢复按钮
                                    return false;
                                }
                            },
                            success: function (data) {
                                var dataJson = eval('(' + data + ')');
                                if (dataJson.success) {
                                    $("#ui_pro_edit_dialog").dialog('destroy');
                                    $.show_alert("提示", dataJson.msg);
                                    $("#ui_Pro_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                                } else {
                                    $('#ui_pro_edit_btn').linkbutton('enable');
                                    $.show_alert("提示", dataJson.msg);
                                }
                            }
                        });
                    }
                }, {
                    text: '取 消',
                    handler: function () {
                        $("#ui_pro_edit_dialog").dialog('destroy');
                    }
                }],
                onLoad: function () {

                },
                onClose: function () {
                    $("#ui_pro_edit_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }

        //删除用户（可批量）
        function DelProInfo() {
            var rows = $("#ui_Pro_dg").datagrid("getSelected");
            if (rows==null) {
                $.show_alert("提示", "请先选择要删除的项目");
                return;
            }
            $.messager.confirm('提示', '确定删除选中行吗？', function (r) {
                if (r) {
                    var ProjectGuidID = rows.ProjectGuid;
                    //alert(ProjectGuidID);
                    $.ajax({
                        url: "/ProInfo/DelProInfo",
                        data: {
                            ProjectGuid: ProjectGuidID
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", "删除成功！");
                                $("#ui_Pro_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }

        //搜索
        function ui_Pro_searchdata() {

            validateDateTime();

            $("#ui_Pro_dg").datagrid('load', {
                selProjectId: $('#selProjectId').val(),
                selProjectName: $('#selProjectName').val(),
                selStartWarrantyTime: $("#selStartWarrantyTime").datetimebox('getValue'),
                selEndWarrantyTime: $("#selEndWarrantyTime").datetimebox('getValue'),
                selUserManager: $('#selUserManager').val(),
            });
            $("#ui_Pro_dg").datagrid('clearSelections').datagrid('clearChecked');
        }
        //搜索清空
        function ui_Pro_cleardata() {
            $('#selProjectId').val(''),
            $('#selProjectName').val(''),
            //$('#selStartWarrantyTime').val(''),
            //$('#selEndWarrantyTime').val(''),
            $('#selUserManager').val(''),
            $('#selStartWarrantyTime').datebox('setValue', '');
            $('#selEndWarrantyTime').datebox('setValue', '');

            $("#ui_Pro_dg").datagrid('clearSelections').datagrid('clearChecked');
        }
        //时间转换
        function getTime(/** timestamp=0 **/) {
            var ts = arguments[0] || 0;
            var t, y, m, d, h, i, s;
            t = ts ? new Date(ts * 1000) : new Date();
            y = t.getFullYear();
            m = t.getMonth() + 1;
            d = t.getDate();
            h = t.getHours();
            i = t.getMinutes();
            s = t.getSeconds();
            // 可根据需要在这里定义时间格式
            return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d);
        }

        function validateDateTime() {
            console.log("hello world");

            var v1 = $("#selStartWarrantyTime").datetimebox('getValue');
            var date1 = new Date(v1);
            console.log(date1);
            var v2 = $("#selEndWarrantyTime").datetimebox('getValue');
            var date2 = new Date(v2);
            console.log(date2);
            if (v1 == '' || v2 == '') {
                return true;
            }
            console.log(date1);
            console.log(date2);
            if (date1 < date2) {
                console.log(date1 + "<" + date2);
                //var diff = DateDiff(date1, date2);
                //if (diff > 30) {
                //    $.messager.alert('提示', '时间段不能超过30天！');
                //}
                return true;
            }
            console.log(date1 + "!<" + date2);

            $.messager.alert('提示', '开始时间要小于结束时间！');

            return false;
        }


        //经纬度验证
        $.extend($.fn.validatebox.defaults.rules, {
            checkLongitude: {
                validator: function (value) {
                    return /^-?(([1-9]\d?)|(1[1-7]\d)|180)(\.\d{1,10})?$/.test(value);
                },
                message: '经度格式不正确'
            },
            checkLatitude: {
                validator: function (value) {
                    return /^-?(([1-8]\d?)|([1-8]\d)|90)(\.\d{1,10})?$/.test(value);
                },
                message: '纬度格式不正确'
            }
        });
        //弹出经纬度拾取页面
        function MapPickup(data) {
            $("<div/>").dialog({
                id: "ui_MapPickup_dialog",
                href: "/Map/Index",
                title: "地图拾取",
                height: 570,
                width: 910,
                modal: true,
                buttons: [{
                    id: "ui_MapPickup_btn",
                    text: '确 定',
                    handler: function () {

                        var arr = $("#lnglat").val().split(',');

                        $("#txtLongitude").val(arr[0]);
                        $("#txtLatitude").val(arr[1]);


                        $("#ui_MapPickup_dialog").dialog('destroy');
                    }
                }, {
                    text: '取 消',
                    handler: function () {
                        $("#ui_MapPickup_dialog").dialog('destroy');
                    }
                }],
                onLoad: function () {

                },
                onClose: function () {
                    $("#ui_MapPickup_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }
    </script>


</head>
<body>
    <div id="ui_user_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'north',split:true,border:true,collapsed:false" title="搜索条件" style="height:74px;">
            <div id="ui_user_search">
                <table class="tableForm" style="width: 99%; height: 100%; background: #F5F5F5;">
                    <tr>
                        <th>
                            项目编号：
                        </th>
                        <td>
                            <input name="selProjectId" id="selProjectId" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            项目名称：
                        </th>
                        <td>
                            <input name="selProjectName" id="selProjectName" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>

                        <th>
                            用户联系人：
                        </th>
                        <td>
                            <input name="selUserManager" id="selUserManager" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>
                        <th>
                            质保期：
                        </th>
                        <td>
                            开始时间：
                            <input name="selStartWarrantyTime" id="selStartWarrantyTime" class="easyui-datebox"
                                   editable="false" style="width:150px;height:22px;" />
                        </td>
                        <td>
                            结束时间：
                            <input name="selEndWarrantyTime" id="selEndWarrantyTime" class="easyui-datebox"
                                   editable="false" style="width:150px;height:22px;" />
                        </td>
                        <td>
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                               onclick="ui_Pro_searchdata();">搜索</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                               onclick="ui_Pro_cleardata();">清空条件</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div data-options="region:'center',border:false">
            <table id="ui_Pro_dg" data-options="fit:true,border:false"></table>
        </div>
    </div>
    <input type="hidden" name="strLocaId" id="strLocaId" value="">
</body>
</html>
